/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
/*
 * BindFieldRequire.java
 *
 * Created on 27 March 2006, 07:00
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package blueprint4j.utils;

/**
 *
 * @author Jasper van der Bijl
 * Setting visibility requirements on other fields from data entered in this field
 */
public class BindFieldRequire {
    
    private VectorBindFieldInterface vectorField = new VectorBindFieldInterface();
    private Object value = null;
    private boolean visible = false;
    
    /** Creates a new instance of BindFieldRequire */
    public BindFieldRequire(VectorBindFieldInterface vectorField,Object value,boolean visible) {
        this.vectorField = vectorField;
        this.value = value;
        vectorField.setVisibleByDefault(false);
        this.visible = visible;
    }
    
    public VectorBindFieldInterface getVectorField() {
        return vectorField;
    }
    
    public Object getValue() {return value;}
    
    public boolean getVisible() {return visible;}
    
    public boolean determine(BindFieldInterface owner) throws BindException {
        if (
                (owner.getObject() == null && value == null)||
                (owner.getObject() != null && (owner.getObject() instanceof String) && owner.getObject().toString().length() == 0 && value == null)||
                (owner.getObject() != null && value != null && value.equals(owner.getObject())) ||
                (owner.getObject() != null && value != null && value.toString().equals(owner.getValueAsString()))
                ) {
            return true;
        }
        return false;
    }
    
}
